package com.yvdedu.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yvdedu.service.UserService;

@Controller
public class Reg_Controller {

	private UserService us = new UserService();

	@RequestMapping("/reg.do")
	@ResponseBody
	public String hander(HttpServletRequest request, HttpSession session) {
		String userName = request.getParameter("userName");
		String pwd = request.getParameter("pwd");
		String pwd2 = request.getParameter("pwd2");
		String yzm = request.getParameter("yzm");
		String code = (String) session.getAttribute("rand");
		if (!yzm.equalsIgnoreCase(code)) {
			return "codeErr";
		} else if (!pwd.equals(pwd2)) {
			return "different";
		} else {
			if (!"".equals(userName) && !"".equals(pwd)) {
				String str = us.reg(userName, pwd);
				if (str == "success") {
					return "true";
				} else {
					return "false";
				}
			} else {
				return null;
			}
		}
	}

	@RequestMapping("/register")
	public String handler() {

		return "register";
	}
}
